//
//  FGFileManager.h
//  FGKit_Example
//
//  Created by Lu feng on 2020/4/8.
//  Copyright © 2020 大风哥. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_OPTIONS(NSInteger, FGDirectoryType) {
    FGDirectoryType_document = 1, //Documents目录
    FGDirectoryType_cache, //Caches目录
    FGDirectoryType_temp, //tmp目录
};

//error domain and codes
typedef NS_ERROR_ENUM(FGErrorDomain, FGFileManagerError) {
    FGFileManagerError_exist = 620, //文件/文件夹已存在
    FGFileManagerError_notExist = 621, //文件/文件夹不存在
    FGFileManagerError_createEmptyFileFailure = 622, //空文件创建失败
};

@interface FGFileManager : NSObject

/**
 * 创建目录
 * pathComponent: @"89/open/av/92"
 */
+ (NSError *)createDirectoryWithPathComponent:(NSString *)pathComponent directoryType:(FGDirectoryType)dirType;
+ (NSError *)createDirectoryWithPath:(NSString *)dirPath;


/**    默认disableiCloudBackup = yes     */
+ (NSError *)createFileWithData:(NSData *)data overwrite:(BOOL)overwrite pathComponent:(NSString *)pathComponent directoryType:(FGDirectoryType)dirType;
/**
 * 创建文件
 * overwrite:是否覆盖原来的
 * pathComponent: @"89/open/av/92",@"89/open/av/92.txt"
 */
+ (NSError *)createFileWithData:(NSData *)data overwrite:(BOOL)overwrite pathComponent:(NSString *)pathComponent directoryType:(FGDirectoryType)dirType disableiCloudBackup:(BOOL)disableiCloudBackup;


/**    默认disableiCloudBackup = yes     */
+ (NSError *)createFileWithData:(NSData *)data overwrite:(BOOL)overwrite filePath:(NSString *)filePath;
+ (NSError *)createFileWithData:(NSData *)data overwrite:(BOOL)overwrite filePath:(NSString *)filePath disableiCloudBackup:(BOOL)disableiCloudBackup;

/**
 * 删除文件/文件夹
 * pathComponent: @"89/open/av/92",@"89/open/av/92.txt"
 */
+ (NSError *)removeItemWithPathComponent:(NSString *)pathComponent directoryType:(FGDirectoryType)dirType;
+ (NSError *)removeItemWithPath:(NSString *)path;


/**    沙盒目录     */
+ (NSString *)shaHeDirectory:(FGDirectoryType)dirType;
/**    根据类型拼接路径     */
+ (NSString *)pathForPathComponent:(NSString *)pathComponent directoryType:(FGDirectoryType)dirType;



/**    单个文件的大小   单位: 字节     */
+ (unsigned long long)fileSizeAtPath:(NSString *)filePath;
/**    文件夹的大小(递归遍历所有文件文件夹)  单位: 字节     */
+ (unsigned long long)folderSizeAtPath:(NSString *)folderPath;


@end



//Documents目录路径
#define kDocumentDirectory NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject
//Caches目录路径
#define kCacheDirectory NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject
//tmp目录路径
#define kTempDirectory NSTemporaryDirectory()

/**    方法调用中最终拼接好的文件路径 (公共方法 + (NSString *)pathForPathComponent:(NSString *)pathComponent directoryType:(FGDirectoryType)dirType 和不需要拼接路径的方法除外)     */
FOUNDATION_EXPORT NSString *_FGFileManager_filePath;
